package console;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

public class Axis extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private double lenght;
	private int y;
	private int scale = 15;
	private int heightMedium=5;
	private int heightMaximum=10;
	private int[] stateTab;
	private Color col;
/**
 * 
 * @param p_lenght
 * @param p_numberOfProcces
 * @param p_scale
 * @param p_heightMedium
 * @param p_heightMaximum
 */
	public Axis(int p_lenght, int p_numberOfProcces, int p_scale, int p_heightMedium, int p_heightMaximum, int [] sTab, Color color) {
		this.lenght = p_lenght;
		this.y = p_numberOfProcces;
		this.scale=p_scale;
		this.heightMaximum=p_heightMaximum;
		this.heightMedium=p_heightMedium;
		this.stateTab = sTab;
		this.col = color;
		this.setPreferredSize(new Dimension((p_lenght*scale)+10, 35));
		setBackground(Color.white);
		setForeground(Color.white);
	}

	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		//najpierw nalezy wyrysowac wykres a na koncu os, zeby nadpisac kolory
		g.setColor(col);
		for(int i = 0; i< this.lenght; i++){
			int height = stateTab[i];
			if(height==1){
				g.fillRect(i*scale, (heightMaximum-heightMedium), scale, heightMedium);
			}else if(height==2){
				g.fillRect(i*scale, 0, scale, heightMaximum);
			}
		}

		g.setColor(Color.black);
		for (int i = 0; i <= this.lenght * scale; i++) {
			if ((i % (scale*5)) == 0) {
				g.fillRect(i, 0 , 1, heightMaximum);
			} else {
				if ((i % scale) == 0) {
					g.fillRect(i, (heightMaximum-heightMedium) , 1, heightMedium);
				} else
					g.fillRect(i, (heightMaximum-1), 1, 1);
			}
		}
	}

}
